use crate::dao;
use crate::runtime::error::MagicBoxError;
use crate::runtime::response::{Code, MagicBoxResponse};
use crate::runtime::result::MagicBoxResult;

#[tauri::command(rename_all = "snake_case")]
pub(crate) async fn invoke_get_setting(name: String) -> MagicBoxResult<MagicBoxResponse<String>> {
    let setting = dao::setting::get_setting_value(name.as_str());
    if setting.is_none() {
        return Err(MagicBoxError::new(Code::ConfigNotExists, "配置不存在"));
    }

    Ok(MagicBoxResponse::new_success(setting.unwrap()))
}